package jmine.tec.services.api.errorlistener;

import java.util.Collection;
import java.util.List;

import jmine.tec.services.ServicesController;
import jmine.tec.utils.register.Receiver;

/**
 * Registro de {@link ServiceErrorListener} utilizado para registrar listeners pelo spring spring no {@link ServicesController}.
 * 
 * @author Rafael Volpato
 * @date Nov 18, 2009
 */
public class ServiceErrorListenerRegistry implements Receiver<ServiceErrorListener> {

    private ServicesController servicesController;

    /**
     * @param servicesController the servicesController to set
     */
    public void setServicesController(ServicesController servicesController) {
        this.servicesController = servicesController;
    }

    /**
     * {@inheritDoc}
     */
    public void register(Collection<? extends ServiceErrorListener> registers) {
        if (registers != null) {
            List<ServiceErrorListener> serviceErrorListeners = this.servicesController.getServiceErrorListeners();
            for (ServiceErrorListener serviceErrorListener : registers) {
                if (!serviceErrorListeners.contains(serviceErrorListener)) {
                    serviceErrorListeners.add(serviceErrorListener);
                }
            }

        }
    }
}
